<cc:page type="normal" style="standard" showSidebar="false" showHeader="true" />
<cc!>
    public String executePost(String host,net.sf.json.JSONObject jsonObject)
    {
        java.net.HttpURLConnection httpURLConnection = null;
        String strReturn ="";
        try {
            java.net.URL url = new java.net.URL(host);
            httpURLConnection = (java.net.HttpURLConnection)url.openConnection();
            httpURLConnection.setConnectTimeout(3000);
            httpURLConnection.setReadTimeout(10000);
            //设置是否向httpURLConnection输出
            httpURLConnection.setDoOutput(true);
            //设置是否从httpURLConnection读入
            httpURLConnection.setDoInput(true);
            //设置是否使用缓存
            httpURLConnection.setUseCaches(false);
            httpURLConnection.setRequestMethod("POST");
            //设置使用标准编码格式编码参数的名-值对
            httpURLConnection.setRequestProperty("Content-Type", "application/json;charset=utf-8");

            java.io.OutputStreamWriter outputStreamWriter = new java.io.OutputStreamWriter(httpURLConnection.getOutputStream(), "UTF-8");
            outputStreamWriter.write(jsonObject.toString());
            outputStreamWriter.flush();
            outputStreamWriter.close();

            //得到响应状态码的返回值 responseCode
            int responseCode = httpURLConnection.getResponseCode();

            if (200== responseCode) {
                StringBuffer stringBuffer = new StringBuffer();

                java.io.InputStream inputStream = httpURLConnection.getInputStream();
                String strLine = "";
                java.io.BufferedReader bufferedReader = new java.io.BufferedReader(new InputStreamReader(inputStream, "UTF-8"));

                while (null != (strLine = bufferedReader.readLine())) {
                    stringBuffer.append(strLine);
                }
                bufferedReader.close();

                strReturn =   stringBuffer.toString();
            }
        } catch (java.net.MalformedURLException e) {
            e.printStackTrace();

        } catch (IOException e) {
            e.printStackTrace();

        } finally {
            if (null != httpURLConnection) {
                //断开连接
                httpURLConnection.disconnect();
            }
        }
        return strReturn;
    }
</cc>
<cc>
        
        // 合同同步到OA
        CCService cs = new CCService(userInfo);
        String contract_async_url_oa = "http://59.110.52.142:9988/api/CertifTransfer/AsyncCertif_CrmToOA?";
        String id = request.getParameter("id")==null?"":request.getParameter("id")+"";
        net.sf.json.JSONObject resultJson = new net.sf.json.JSONObject();

        // 查询必须字段
        List<CCObject> xczbllcList =  cs.cquery("xczbllc"," id = '"+ id +"'");

        List<CCObject> userList = cs.cqlQuery("","select ddid from ncry where dyyh = '"+ xczbllcList.get(0).get("ownerid") +"'");
        if (userList.size() <= 0) {
            out.print("数据不全，没有查询合同的发起人。");

        }
        String creator_id = userList.get(0).get("ddid") == null? "": userList.get(0).get("ddid").toString();


        //获取流程编码
        String lcbm = xczbllcList.get(0).get("lcbm") == null? "": xczbllcList.get(0).get("lcbm").toString();

        // 获取招商负责人
        String zsfzr = xczbllcList.get(0).get("zsfzr") == null? "": xczbllcList.get(0).get("zsfzr").toString();
        List<CCObject> zsfzrList = cs.cqlQuery("","select ddid from ncry where dyyh = '"+  zsfzr  +"'");
        String zsfzr_id = zsfzrList.get(0).get("ddid") == null? "": zsfzrList.get(0).get("ddid").toString();

        //获取房产
        String fc = xczbllcList.get(0).get("fc") == null? "": xczbllcList.get(0).get("fc").toString();
        List<CCObject> fcList = cs.cqlQuery("","select name from fc where id = '"+  fc +"'");
        String fc_name = fcList.get(0).get("name") == null? "": fcList.get(0).get("name").toString();

        //获取区域融资总监
        String qyrzzj = xczbllcList.get(0).get("qyrzzj") == null? "": xczbllcList.get(0).get("qyrzzj").toString();
        List<CCObject> qyrzzjList = cs.cqlQuery("","select ddid from ncry where dyyh = '"+  qyrzzj +"'");
        String qyrzzj_id = qyrzzjList.get(0).get("ddid") == null? "": qyrzzjList.get(0).get("ddid").toString();

        //获取客户真名
        String khzm = xczbllcList.get(0).get("khzm") == null? "": xczbllcList.get(0).get("khzm").toString();
        //获取应办证日期
        String ybzrq = xczbllcList.get(0).get("ybzrq") == null? "": xczbllcList.get(0).get("ybzrq").toString();
        //获取办理产证需达到的纳税额(万元)
        String blcznse = xczbllcList.get(0).get("blcznse") == null? "": xczbllcList.get(0).get("blcznse").toString();
        //获取合同约定注册日期
        String ydzcrq = xczbllcList.get(0).get("ydzcrq") == null? "": xczbllcList.get(0).get("ydzcrq").toString();
        //获取实际注册日期
        String sjzcrq = xczbllcList.get(0).get("sjzcrq") == null? "": xczbllcList.get(0).get("sjzcrq").toString();
        //获取注册公司名称
        String zcgsmc = xczbllcList.get(0).get("zcgsmc") == null? "": xczbllcList.get(0).get("zcgsmc").toString();
        //获取实际纳税金额
        String sjnsje = xczbllcList.get(0).get("sjnsje") == null? "": xczbllcList.get(0).get("sjnsje").toString();

        //获取税收考核方式
        String sskhfs = xczbllcList.get(0).get("sskhfs") == null? "": xczbllcList.get(0).get("sskhfs").toString();
        //获取纳税证明图片
        String nszmtp = xczbllcList.get(0).get("nszmtp") == null? "": xczbllcList.get(0).get("nszmtp").toString();
        //获取营业执照
        String yyzz = xczbllcList.get(0).get("yyzz") == null? "": xczbllcList.get(0).get("yyzz").toString();
        //获取销售合同流程
        String xshtlc = xczbllcList.get(0).get("xshtlc") == null? "": xczbllcList.get(0).get("xshtlc").toString();
        //获取销售合同照片
        String xshttp = xczbllcList.get(0).get("xshttp") == null? "": xczbllcList.get(0).get("xshttp").toString();

        resultJson.put("lcbm", lcbm);
        resultJson.put("zsfzr", zsfzr_id);
        resultJson.put("fc", fc_name);
        resultJson.put("qyrzzj", qyrzzj_id);
        resultJson.put("khzm", khzm);
        resultJson.put("ybzrq", ybzrq);
        resultJson.put("blcznse", blcznse);
        resultJson.put("ydzcrq", ydzcrq);
        resultJson.put("sjzcrq", sjzcrq);
        resultJson.put("zcgsmc", zcgsmc);
        resultJson.put("sjnsje", sjnsje);
        resultJson.put("nszmtp", nszmtp);
        resultJson.put("yyzz", yyzz);
        resultJson.put("xshtlc", xshtlc);
        resultJson.put("xshttp", xshttp);


        //List<CCObject> ownerList = cs.cqlQuery("","select ownerid from xczbllc where id = '"+ id +"'");

        // OA workflow发起人
        //List<CCObject> userList = cs.cqlQuery("","select ddid from ncry where dyyh = '"+  ownerList.get(0).get("ownerid") +"'");
        //if (userList.size() <= 0) {
        //out.print("数据不全，没有查询合同的发起人。");

        //}
        //String creator_id = userList.get(0).get("ddid") == null? "": userList.get(0).get("ddid").toString();

        if (creator_id.length() > 0) {
            String result = executePost(contract_async_url_oa + "creator_id=" + creator_id, resultJson);
            if (result.equals("") || result == null) {
                out.print("返回result为空");
            } else {
                // out.print(result);
                if (result.equals("101")) {
                    // trigger.addErrorMessage("数据不全，查询不到对应OA用户LOGINID");
                } else {
                    String[] arr = result.split(",");
                    if (arr.length > 0) {
                        // arr[0] = arr[0].substring(1);
                        xczbllcList.get(0).put("oadjid", arr[0]);
                        // arr[1] = arr[1].substring(0, arr[1].length() - 1);
                        xczbllcList.get(0).put("oaspdz", "http://59.110.52.142:9988/api/Transfer/proxyContract?request_id=" + arr[0] + "&login_id=" + arr[1]);
                        cs.update(xczbllcList.get(0));
                    } else {
                        // err_msg = "接口返回数据格式不正确";
                    }
                }
            }
            out.print(result);
        } else {
        }
        
        out.print("111");
</cc>

